# 滚动到底部
js = "window.scrollTo(0, 10000000);"
remdr$executeScript(js, args = list("dummy"))

js="var q=document.documentElement.scrollTop=10000000"
remdr$executeScript(js, args = list("dummy"))
remdr$screenshot(display = 1)

haoping <- remdr$findElement(using = "css", '.filter-list > li:nth-child(4)')

haoping$getElementAttribute("data-num")

webElem <- remdr$findElement(using = "tag", value = "h2")
test <- remdr$findElement(using = "id", "comment")
test <- remdr$getTitle()
test
test$getElementAttribute(attrName = "data-anchor")


# test source
mypage <- remdr$getPageSource()


page <- read_html(mypage[[1]])
html_nodes(page, ".filter-list > li:nth-child(4)") %>% html_text()
html_nodes(page, "comment")

mynode <- html_nodes(page, ".filter-list > li:nth-child(4)") 
mynode
rvest::html_attr(mynode, "data-num")


jdpage = rdom::rdom("https://item.jd.com/1640917.html")
html_nodes(jdpage)

startServer()
remdr <- remoteDriver$new()
remdr$open()
remdr$navigate("http://www.google.com")
remdr$navigate("http://www.bbc.co.uk")
remdr$goBack()
remdr$goForward()
remdr$quit()





webpage <- read_html(url) 

webpage.new <-  gsub(pattern = "<meta.*?>|<link.*?>|<img.*?>|<a.*?>|</a>|\r\n|<script.*?</script>|<style.*?</style>",
                     "",x = webpage)

webpage.new <- read_html(webpage.new)

html_nodes(webpage.new, ".p-price .price")

hg_tlmgr_install_win("xCJK2uni.sty")



remdr <- remoteDriver(remoteServerAddr = "192.168.77.4", 
                      browserName = "firefox", 
                      version = "2.1.1", platform = "WINDOWS",
                      port = 4444L)

try({
  hg_rs_get_sessions_id(remdr)
  # hg_rs_close(remdr)
  hg_rs_open(remdr)
}, TRUE)
remdr$navigate("http://www.zhonghaoguang.com")
js  = "window.document.body.scrollTop = document.body.scrollHeight;"
remdr$executeScript(js, args = list("dummy"))



tryCatch({
  suppressMessages({
    js = "var q = document.body.scrollHeight/2; window.scrollTo(0, q);"
    remdr$executeScript(js, args = list("dummy"))
  })
},
error = function(e) {
  message(e, "\n")
  return(0)
})

hg_rs_scroll_ntimes_height(remdr)
